import { DataTypes } from "sequelize";
import datasource from '../../framework/datasource'

const WordType = datasource.define('wordType', {
    name: DataTypes.STRING
}, {
    createdAt: "createTime",
    updatedAt: 'updateTime'
})

const Word = datasource.define("word", {
    id: {
        type: DataTypes.INTEGER(),
        autoIncrement: true,
        allowNull: false,
        primaryKey: true
    },
    word: DataTypes.STRING,
}, {
    createdAt: "createTime",
    updatedAt: 'updateTime'
})

WordType.hasMany(Word, { foreignKey: 'typeId', onDelete: 'CASCADE' })
const Translations = datasource.define('translations', {
    translation: DataTypes.TEXT,
    type: DataTypes.STRING,

},
    { createdAt: "createTime", updatedAt: 'updateTime' })

Word.hasMany(Translations, {
    foreignKey: 'wordId',
    onDelete: 'CASCADE',
})

const Phrases = datasource.define('phrases', {
    id: {
        type: DataTypes.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        allowNull: false
    },
    phrase: DataTypes.TEXT,
    translation: DataTypes.TEXT,
}, {
    createdAt: "createTime",
    updatedAt: 'updateTime'
})
Word.hasMany(Phrases, {
    foreignKey: 'wordId',
    onDelete: 'CASCADE',
})

export {
    Word,
    Translations,
    Phrases,
    WordType
}